package com.shape;

public class Square implements Shape {
    private double side;

    public Square(double side) {
        if (side <= 0) {
            throw new IllegalArgumentException("边长必须大于0");
        }
        this.side = side;
    }

    @Override
    public double getArea() {
        return side * side;
    }

    @Override
    public double getPerimeter() {
        return 4 * side;
    }

    @Override
    public String getName() {
        return "正方形";
    }

    public double getSide() {
        return side;
    }

    @Override
    public String toString() {
        return String.format("正方形(边长=%.2f) - 面积: %.2f, 周长: %.2f",
                side, getArea(), getPerimeter());
    }
}